package kr.co.doriclassic.chapter22.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class ArrayListTest {
	public static void main(String[] args) {
		ArrayList<String> arList = new ArrayList<>();
		arList.add("MILK");
		
		ArrayList<String> subList = new ArrayList<>();
		subList.add("BREAD");
		subList.add("BUTTER");
		
		arList.addAll(subList);
		arList.add(1, "APPLE");
		
		for (String str : arList) {
			System.out.println(str);
		}
		
		Collections.sort(arList);
		
		//사용자 클래스를 받을 때는 equals 써야 한다.
		System.out.println("BREAD 있나요?"+arList.contains("BREAD"));
		
		
		
		//컬렉션을 배열로 저장
		Object[] arr = arList.toArray();
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i]+"\t");
		}
		
		String[] strArr = new String[arList.size()];
		arList.toArray(strArr);
		for (int i = 0; i < strArr.length; i++) {
			System.out.println(strArr[i]+"\t");
		}
		System.out.println();
		arList.clear();
		
		System.out.println("Empty?:"+arList.isEmpty());
		/*boolean result = arList.contains("BREAD");
		
		arList.remove(1);//인덱스가 올 수도 있고 실제 값이 올 수도 있으나
		arList.remove("BREAD");//내가 만든 클래스는 equals 만들어야 한다.
		
		arList.clear();
		
		System.out.println(result);*/
		
		for (String str : arList) {
			System.out.println(str);
		}
		
		System.out.println("================");
		
		for (int i = 0; i < arList.size(); i++) {
			System.out.println(arList.get(i));
		}
	
	}
}
